package Cart_Servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Cart_Function.Cart_Function;

/**
 * Servlet implementation class EmptyCart_Servlet
 */
@WebServlet("/EmptyCart_Servlet")
public class EmptyCart_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EmptyCart_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=utf-8");
		String uri[] = request.getHeader("Referer").split("/");
		String msg;
		
		String user = (String) request.getSession(true).getAttribute("UserName");
		
		if(new Cart_Function().empty(user)){
			msg = "购物车已清空！";
		}else
			msg = "购物车为空！无需清空";
		request.getRequestDispatcher(uri[uri.length-1]).forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
